<?php
/**
 * Created by PhpStorm.
 * User: ����
 * Date: 2015/12/11
 * Time: 11:06
 */

namespace app\api\controllers;


use app\api\Response;
use app\models\Patent;
use yii\helpers\ArrayHelper;
use yii\web\Controller;

class PatentController extends Controller
{

    public function actionList($pageNow, $pageSize){

        $list = Patent::getList($pageNow, $pageSize);
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($list));
    }

    public function actionDetail($id){

        $detail = Patent::findOne(['id'=>$id]);
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($detail));
    }
    
    /**
    * 搜索功能
    * @param type $patentname
    * @return type
    */
    public function actionSearch($patentname) {
        $patentnames= Patent::find()
              ->where(['or',['like','author',$patentname],['like','patentname',$patentname]])
              ->all();
      Response::setHeader();
      return json_encode(\yii\helpers\ArrayHelper::toArray($patentnames));
    }


}